﻿using System;
using XNAGameEngine.GUI;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using XNAGameEngine.Input;
using Microsoft.Xna.Framework.Input;
using XNAGameEngine;
using XNAGameEngine.GameState;

namespace XNAGameEngine
{
    class LoadButton : GUIObject, IMouseEventListener, IInputListener
    {
        public LoadButton(IManagerGUI guiManager)
            : base(guiManager)
        {
        }

        public override void Initialize()
        {
            base.Initialize();

            GameEngine.GetService<IManagerMouseEvents>().ToggleMouseEventListener(true, this);
            GameEngine.GetService<IManagerInput>().ToggleInputListening(true, this);
            _texture = GameEngine.GameContent.Load<Texture2D>("Content\\Buttons\\LoadImage");
            _position = new Vector2((800 - _texture.Width), 80);
            _boundingBox = new Rectangle((int)_position.X, (int)_position.Y, _texture.Width, _texture.Height);
        }

        public override void Cleanup()
        {
            base.Cleanup();

            GameEngine.GetService<IManagerMouseEvents>().ToggleMouseEventListener(false, this);
            GameEngine.GetService<IManagerInput>().ToggleInputListening(false, this);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        #region IMouseEventListener Members

        public Rectangle BoundingBox
        {
            get { return _boundingBox; }
        }

        public void OnMouseEnter()
        {
            _textureTint = Color.Yellow;
        }

        public void OnMouseExit()
        {
            _textureTint = Color.White;
        }

        public void OnMouseClick(MouseClick input)
        {
            if (input == MouseClick.LEFT)
            {
                Console.WriteLine("Changing to Load state");
                //GameEngine.GetService<IManagerGameState>().ChangeState("Load");
            }
        }

        #endregion

        #region IInputListener Members

        public void InputPressed(InputMessage input)
        {
            switch (input._key)
            {
                case Keys.L:
                    Console.WriteLine("Changing to Load state");
                    //GameEngine.GetService<IManagerGameState>().ChangeState("Load");
                    break;
            }
        }

        public void InputReleased(InputMessage input)
        {
        }

        public void InputHeld(InputMessage input)
        {
        }

        public event ManagerInput.InputRegisterListenerEventHandler ThrowUnregisterListenerEvent;

        #endregion
    }
}
